package com.verisette.ncos.web.accesscontrol.action;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import org.corp.agi.service.bean.ServiceRequest;
import org.corp.agi.service.bean.ServiceResponse;
import org.corp.agi.service.bean.UserBean;
import org.corp.agi.web.action.BaseAction;
import org.corp.agi.web.constant.WebConstant;
import org.corp.agi.web.util.ServiceRequestFactory;
import com.verisette.ncos.service.accesscontrol.gateway.CustomAccessControlService;

@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class CustomLogoutAction extends BaseAction {

	private Logger logger = Logger.getLogger(CustomLogoutAction.class);
	
	
	private  CustomAccessControlService customAccessControlService;
	@Autowired
	@Required
	public void setCustomAccessControlService(CustomAccessControlService customAccessControlService) {
		this.customAccessControlService = customAccessControlService;
	}
	
	public String execute() throws Exception {
		if(httpServletRequest.getSession(false) != null)
		{
			ServiceRequest<UserBean> request = ServiceRequestFactory.getNewServiceRequest(httpServletRequest);
			UserBean masUser = (UserBean) httpServletRequest.getSession().getAttribute(WebConstant.SESSION_USERBEAN_KEY);
			request.setValueObject(masUser);
	        
	        ServiceResponse<UserBean> response = customAccessControlService.customLogout(request);
			httpServletRequest.getSession().invalidate();
		}
		return "forceToStartAction";
	}
}
